package com.stox.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stox.converter.BeanMapper;
import com.stox.manager.ScripManager;
import com.stox.model.Scrip;
import com.stox.model.entity.ScripEntity;

@Controller
@RequestMapping(value="/scrips")
public class ScripController {

	@Autowired
	private ScripManager scripManager;
	
	@Autowired
	private BeanMapper beanMapper;
	
	@ResponseBody
	@SuppressWarnings("unchecked")
	@Cacheable("com.stox.model.entity.ScripEntity")
	@RequestMapping(value="/{exchangeCode}", method=RequestMethod.GET, produces="application/json")
	public List<Scrip> findByExchangeCode(@PathVariable("exchangeCode") String exchangeCode){
		List<ScripEntity> scripEntities = scripManager.findByExchangeCode(exchangeCode); 
		return beanMapper.map(scripEntities, ArrayList.class, Scrip.class);
	}

}
